

from multiprocessing import Queue

""" TO BE SET BY LOOPER MODULE """
graph_queue = None
script_id = None

ADD_DATA = "AddData"
CREATE_GRAPH = "CreateGraph"

POP_GRAPH = "PopGraph"
OBJ_GRAPH = "ObjGraph"
PARETO_GRAPH = "ParetoGraph"

gid = 0


def GraphAPIFactory(type, title, x_axis_name, y_axis_name):
    global gid
    obj = {}
    obj["action"] = CREATE_GRAPH
    obj["x_axis_name"] = x_axis_name
    obj["y_axis_name"] = y_axis_name
    obj["graph_type"] = type
    obj["script_id"] = script_id
    obj["graph_id"] = gid
    obj["title"] = title
    
    graph_queue.put(obj)
    gid += 1
    return GraphAPI(script_id, gid-1)

class GraphAPI(object):
    def __init__(self, script_id, graph_id):
        self.script_id = script_id
        self.graph_id = graph_id
        
    def addData(self, x, y, id=None):
        obj = {}
        obj["action"] = ADD_DATA
        obj["script_id"] = self.script_id
        obj["graph_id"] = self.graph_id
        obj["x"] = x
        obj["y"] = y
        obj["id"] = id
        graph_queue.put(obj)
        
